import os
import sys
rootDir = '..'
if (len(sys.argv) == 2):
    rootDir = argv[1]
out = open('todo.txt', 'w')
for dirName, subDirs, fileList in os.walk(rootDir):
    for fname in fileList:
        f = open(dirName + os.sep + fname, 'r')
        try:            
            lineCount = 1
            headerDisplayed = False
            for line in f:
                if line.lower().find("todo") != -1:
                    if not headerDisplayed:
                        out.write("FILE: {0}".format(fname) + os.linesep)
                    out.write("\tLINE {0}: {1}".format(lineCount, line.strip()) + os.linesep)
                lineCount += 1
        except UnicodeDecodeError:
            pass
        f.close()
out.close()
